# -*- coding: utf-8 -*-
"""
Created on Thu Apr 23 21:14:17 2020

@author: Farman
"""

import joblib
import pathlib
import numpy as np
from PIL import Image as img



pred_file = r'D:\Pavia\Pavia\PaviaUniversity\y_pred.joblib'
shape_file = r'D:\Pavia\Pavia\PaviaUniversity\shape_pred.joblib'

pd = joblib.load(pred_file)
shape = joblib.load(shape_file)

pd = np.array(pd, dtype='int8')
h, w, *pad = shape

print('Prediction Result')
print('\tclass\tpixels')
print('-' * 20)

for n in range(pd.min(), pd.max()+1):
    print('\t', n, '\t\t', sum(pd==n))


pd2d = pd.reshape(w, h).swapaxes(0,1)


save_path = pathlib.Path(pred_file).parent / 'Predict'

try:
    pathlib.os.mkdir(save_path)
except:
    pass


for n in range(pd.min(), pd.max() + 1):
    pdx = (pd2d==n) * 250
    pdx = np.array(pdx, dtype='int8')
    pic = img.fromarray(pdx).convert('RGB')
    #pic.show()
    pic.save(save_path / ('Predict-%02d.png'%n))
